package com.xoa.service.guideGoal.impl;

import com.xoa.dao.common.SysCodeMapper;
import com.xoa.dao.department.DepartmentMapper;
import com.xoa.dao.guideGoal.GuideGoalBackMapper;
import com.xoa.dao.sms.SmsMapper;
import com.xoa.dao.users.UsersMapper;
import com.xoa.dao.guideGoal.GuideGoalMapper;
import com.xoa.dao.guideGoal.GuideGoalTypeMapper;
import com.xoa.model.guideGoal.GuideGoal;
import com.xoa.model.guideGoal.GuideGoalType;
import com.xoa.service.guideGoal.GuideGoalService;
import com.xoa.model.calender.Calendar;
import com.xoa.model.common.SysCode;
import com.xoa.model.department.Department;
import com.xoa.model.enclosure.Attachment;
import com.xoa.model.sms.SmsBody;
import com.xoa.model.users.Users;
import com.xoa.service.calendar.CalendarService;
import com.xoa.service.sms.SmsService;
import com.xoa.util.CookiesUtil;
import com.xoa.util.DateFormat;
import com.xoa.util.GetAttachmentListUtil;
import com.xoa.util.ToJson;
import com.xoa.util.common.L;
import com.xoa.util.common.StringUtils;
import com.xoa.util.common.session.SessionUtils;
import com.xoa.util.dataSource.ContextHolder;
import com.xoa.util.page.PageParams;
import com.xoa.util.treeUtil.CheckTree;
import com.xoa.util.guideGoal.GuideGoalTreeUtil;
import com.xoa.util.treeUtil.TreeGirdNode;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * Created by 张丽军 on 2017/7/28.
 */
@Service
public class GuideGoalServiceImpl implements GuideGoalService {

    @Resource
    GuideGoalMapper guideGoalMapper;

    @Resource
    GuideGoalTypeMapper guideGoalTypeMapper;

    @Resource
    UsersMapper usersMapper;

    @Resource
    DepartmentMapper departmentMapper;

    @Resource
    ThreadPoolTaskExecutor threadPoolTaskExecutor;

    @Resource
    SysCodeMapper sysCodeMapper;

    @Resource
    SmsService smsService;

    @Resource
    SmsMapper smsMapper;

    @Resource
    GuideGoalBackMapper guideGoalBackMapper;


    @Resource
    private CalendarService calendarService;


    @Override
    public ToJson<GuideGoal> getSupManageByTypeId(HttpServletRequest request, Integer typeId, Integer page, Integer pageSize, Boolean useFlag) {
        ToJson<GuideGoal> toJson = new ToJson<GuideGoal>(1, "error");
        try {
            Users user = SessionUtils.getSessionInfo(request.getSession(), Users.class, new Users(),CookiesUtil.getCookieByName(request, "redisSessionId"));


            HashMap<String,Object> maps = new HashMap<>();
            PageParams pageParams=new PageParams();
            pageParams.setPage(page);
            pageParams.setPageSize(pageSize);
            pageParams.setUseFlag(useFlag);
            maps.put("page",pageParams);

            maps.put("createrId",user.getUserId());
            maps.put("typeId",typeId);
            List<GuideGoal> list = guideGoalMapper.getSupManageByTypeId(maps);
            if (list != null) {
                for (GuideGoal guideGoal : list) {
                    //时间处理（时间截取）
                    if (!StringUtils.checkNull(guideGoal.getEndTime())) {
                        guideGoal.setEndTime(guideGoal.getEndTime().substring(0, guideGoal.getEndTime().length() - 2));
                    }
                    //责任领导人可以有多个，通过解析
                    String nameStringManage = this.checkAll(guideGoal.getLeaderId());
                    guideGoal.setUserName(nameStringManage);
                    //协办人可以有多个，通过，解析
                    String nameStrings = this.checkAll(guideGoal.getUserId());
                    guideGoal.setUserPrivName(nameStrings);
                }
                toJson.setObj(list);
                toJson.setMsg("ok");
            } else {
                toJson.setMsg("数据信息为空");
            }
            toJson.setTotleNum(pageParams.getTotal());
            toJson.setFlag(0);

        } catch (Exception e) {
            e.printStackTrace();
            toJson.setMsg(e.getMessage());
            toJson.setFlag(1);
        }
        return toJson;
    }


    @Override
    public ToJson<TreeGirdNode> getSupManageMenu(HttpServletRequest request, GuideGoal guideGoal) {
        ToJson<TreeGirdNode> toJson = new ToJson<TreeGirdNode>(1, "error");
        try {
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("userId", request.getSession().getAttribute("userId"));
            map.put("userPriv", request.getSession().getAttribute("userPriv"));
            map.put("deptId", request.getSession().getAttribute("deptId"));
            List<GuideGoalType> list = new LinkedList<GuideGoalType>();//子级
            list = guideGoalTypeMapper.getSupManageMenu(guideGoal);
            List<GuideGoalType> rootList = new ArrayList<GuideGoalType>();//父级
            Iterator<GuideGoalType> total = list.iterator();
            String userId = (String) map.get("userId");
            while (total.hasNext()) {
                GuideGoalType type = total.next();
                //判断parentId是否为0，为0则代表是父级，不为0代表是子级。
                if (type.getParentId() == null || type.getParentId() == 0) {
                    if ("admin".equals(userId)) {
                        rootList.add(type);
                        total.remove();
                        continue;
                    }
                    boolean flag = CheckTree.checkAll(type.getUserId(), map);
                    if (flag) {
                        rootList.add(type);
                        total.remove();
                    }
                }
            }
            GuideGoalTreeUtil sup = new GuideGoalTreeUtil(rootList, list, map);
            List<TreeGirdNode> totalListAdmin = new LinkedList<TreeGirdNode>();
            totalListAdmin = sup.getTreeGirdNode();//得到树节点
            /*if("admin".equals(userId)){
                totalListAdmin=sup.getTreeNode();
			}else{
				totalListAdmin=sup.getTreeNodeMap();
			}*/
            toJson.setObj(totalListAdmin);
            toJson.setMsg("ok");
            toJson.setFlag(0);
        } catch (Exception e) {
            e.printStackTrace();
            toJson.setMsg(e.getMessage());
            toJson.setFlag(1);
        }
        return toJson;
    }

    /**
     * 创建作者:   张丽军
     * 创建日期:   2017年7月28日 下午15:30:00
     * 方法介绍:   督办管理新建接口(************)
     *
     * @param request
     * @param guideGoal
     * @return
     */
    @Override
    public ToJson<GuideGoal> addSupervision(HttpServletRequest request, GuideGoal guideGoal) {
        ToJson<GuideGoal> toJson = new ToJson<GuideGoal>(1, "error");
        try {
            guideGoal.setManagerId(guideGoal.getManagerId().substring(0, guideGoal.getManagerId().length() - 1));
           // supervision.setLeaderId(supervision.getLeaderId().substring(0, supervision.getLeaderId().length() - 1));
            guideGoal.setCreaterId((String) request.getSession().getAttribute("userId"));
            guideGoal.setCreaterTime(DateFormat.getCurrentTime());
            int a = guideGoalMapper.addSupervision(guideGoal);
            //去掉工作日志
//            if(supervision.getStatus()!=null && supervision.getStatus()==7){
//                addAffairs(supervision,request);
//                Supervision supervision1=dljSupervisionMapper.selectByPrimaryKey(supervision.getSid());
//                addToCalender(supervision1,request);//添加到日程安排
//            }
            if(a>0){
                toJson.setObject(guideGoal);
                toJson.setMsg("ok");
                toJson.setFlag(0);
            }else {
                toJson.setMsg("err");
                throw new Exception();
            }
        } catch (Exception e) {
            e.printStackTrace();
            toJson.setMsg(e.getMessage());
            toJson.setFlag(1);
        }
        return toJson;
    }

    /**
     * 创建作者:   张丽军
     * 创建日期:   2017年7月31日 下午15:30:00
     * 方法介绍:   督办删除接口(***********)
     *
     * @param request
     * @param sid
     * @return
     */
    @Override
    public ToJson<GuideGoal> deleteSupervisionBySid(HttpServletRequest request, Integer sid) {
        ToJson<GuideGoal> toJson = new ToJson<GuideGoal>(1, "error");
        try {
            guideGoalMapper.deleteSupervisionBySid(sid);
            if (sid != null) {
                toJson.setMsg("ok");
            } else {
                toJson.setMsg("err");
            }
            toJson.setFlag(0);
        } catch (Exception e) {
            e.printStackTrace();
            toJson.setMsg(e.getMessage());
            toJson.setFlag(1);
        }
        return toJson;
    }


    /**
     * 创建作者:   张丽军
     * 创建日期:   2017年7月31日 下午15:30:00
     * 方法介绍:   督办统计查询列表接口
     *
     * @param
     * @param sid
     * @return
     */
    @Override
    public ToJson<GuideGoal> selectCountList(Map<String, String> mapParamter, Integer sid, String beginDate, String endDate, String typeId) {
        ToJson<GuideGoal> toJson = new ToJson<GuideGoal>(1, "error");
        try {
            String type1 = mapParamter.get("type1");
            String type2 = mapParamter.get("type2");
            String type3 = mapParamter.get("type3");
            String deptId = mapParamter.get("deptId");

            Map<String, Object> objectMap = new HashMap<String, Object>();
            if (!StringUtils.checkNull(beginDate) && !StringUtils.checkNull(endDate)) {
                objectMap.put("beginDate", beginDate);
                objectMap.put("endDate", endDate);
            }
            if (!StringUtils.checkNull(typeId)) {
                objectMap.put("typeId", typeId);
            }

            objectMap.put("deptId", deptId);

            switch (Integer.parseInt(type1)) {
                case 1://按部门统计查询
                    List<Department> deptList = departmentMapper.getAllDepartment();
                    List<GuideGoal> maplist = new LinkedList<GuideGoal>();
                    for (Department dept : deptList) {
                        GuideGoal map = queryCountByDept(dept.getDeptId(), objectMap);
                        map.setDeptName(dept.getDeptName());
                        maplist.add(map);
                    }
                    toJson.setObj(maplist);
                    break;
                case 2://按类别统计查询
                    List<GuideGoalType> list = guideGoalTypeMapper.selectAll();
                    List<GuideGoal> maplist2 = new LinkedList<GuideGoal>();
                    for (GuideGoalType s : list) {
                        GuideGoal sp = queryCountByType(s.getSid(), objectMap);
                        sp.setTypeId(s.getSid());
                        sp.setDeptName(s.getTypeName());
                        maplist2.add(sp);
                    }
                    toJson.setObj(maplist2);
                    break;
                case 3://按状态统计查询
                    GuideGoal sp = queryCount(objectMap);
                    toJson.setObject(sp);
                    break;
                default:
                    break;
            }
        } catch (Exception e) {
            e.printStackTrace();
            toJson.setMsg(e.getMessage());
            L.e("Supervision selectCountList" + e);
        }
        return toJson;
    }


    public ToJson<GuideGoal> getSupAssistDetail(HttpServletRequest request, Integer sid, String bodyId) {
        ToJson<GuideGoal> toJson = new ToJson<GuideGoal>(1, "error");
        try {
            GuideGoal guideGoal2 = new GuideGoal();
            guideGoal2.setSid(sid);
            guideGoal2.setManagerId((String) request.getSession().getAttribute("userId"));
            GuideGoal guideGoal = guideGoalMapper.getSupAssistDetail(guideGoal2);
            //附件处理
            List<Attachment> attachmentList=new ArrayList<Attachment>();
            if(guideGoal.getAttachmentName()!=null&&!"".equals(guideGoal.getAttachmentName())){
                attachmentList= GetAttachmentListUtil.returnAttachment(guideGoal.getAttachmentName(), guideGoal.getAttachmentId(),"xoa" + (String) request.getSession().getAttribute("loginDateSouse"),GetAttachmentListUtil.SUPERVISE);
            }
            guideGoal.setAttachmentList(attachmentList);
//            supervision.setLeaderId(supervision.getLeaderId().substring(0,supervision.getLeaderId().length()-1));
//            supervision.setUserId((String) request.getSession().getAttribute("userId"));
//            String nameStrings=usersService.getUserNameById(supervision.getUserId());
//            supervision.setUserName(nameStrings);
            if (guideGoal != null) {
                if (!StringUtils.checkNull(guideGoal.getBeginTime())) {
                    guideGoal.setBeginTime(guideGoal.getBeginTime().substring(0, guideGoal.getBeginTime().length() - 2));
                }
                if (!StringUtils.checkNull(guideGoal.getEndTime())) {
                    guideGoal.setEndTime(guideGoal.getEndTime().substring(0, guideGoal.getEndTime().length() - 2));
                }
                //责任领导人可以有多个，通过解析
                String nameStringManage = this.checkAll(guideGoal.getLeaderId());
                guideGoal.setUserName(nameStringManage);

                String userId = this.checkAll(guideGoal.getUserId() == null ? "" : guideGoal.getUserId());
                guideGoal.setUserPrivName(userId);

                if(!StringUtils.checkNull(bodyId)){
                    smsMapper.setRead((String) request.getSession().getAttribute("userId"),Integer.valueOf(bodyId));
                }
                toJson.setObject(guideGoal);
                toJson.setMsg("ok");
            } else {
                toJson.setMsg("数据为空");
            }
            toJson.setFlag(0);
        } catch (Exception e) {
            e.printStackTrace();
            toJson.setMsg(e.getMessage());
            L.e("SupervisionServiceImpl getSupAssistDetail:" + e);
        }
        return toJson;
    }

    /**
     * 创建作者:   张丽军
     * 创建日期:   2017-8-5 上午11:22:25
     * 方法介绍:   userid串处理
     * 参数说明:   @return
     *
     * @return Supervision
     */
    public String checkAll(String checkString) {
        StringBuffer sb = new StringBuffer("");
        Map<String, Object> mapParam = new HashMap<String, Object>();
        //"|"转义字符串  所以必须用\\进行转义 因为 而且取出数组长度不确定
        //String[] checkStrings=(checkString==null?"":checkString).split(",");
//        if(checkStrings.length==0){
//            return sb.toString();
//        }
        if (checkString != null) {


            String checkUserId = checkString.substring(0, checkString.length() == 0 ? 0 : (checkString.length() - 1));
            if (checkUserId != null && !"".equals(checkUserId)) {
                checkUserId = "'" + checkUserId.replace(",", "','") + "'";
                mapParam.put("checkUserId", checkUserId);
                List<String> listCheckUserId = usersMapper.getUserNames(mapParam);
                sb.append(this.getString(listCheckUserId));
                for (String s : listCheckUserId) {
                    sb.append("");
                }
            } else {
                sb.append("");
            }
        }
        return sb.toString();
    }

   /* public String getString( List<String> Strings){
        StringBuffer sb=new StringBuffer("");
        if(Strings==null){
            return "";
        }
        for(String s:Strings){
            sb.append(s);
            sb.append(",");
        }
        return sb.toString();
    }*/

    /**
     * 创建作者:   杨 胜
     * 创建日期:   2017-8-3 下午5:52:25
     * 方法介绍:   统计
     * 参数说明:   @return
     *
     * @return Supervision
     */
    private GuideGoal queryCount(Map<String, Object> objectMap) {
        GuideGoal sp = guideGoalMapper.queryCount();
        return sp;
    }


    public GuideGoal queryCountByDept(Integer deptId, Map<String, Object> map) {
        GuideGoal paraSup = new GuideGoal();
        paraSup.setDeptId(deptId);
        if (!StringUtils.checkNull((String) map.get("beginDate")) && !StringUtils.checkNull((String) map.get("endDate"))) {
            paraSup.setBeginDate((String) map.get("beginDate"));
            paraSup.setEndDate((String) map.get("endDate"));
        }
        if (!StringUtils.checkNull((String) map.get("typeId"))) {
            paraSup.setTypeId(Integer.parseInt((String) map.get("typeId")));
        }
        paraSup = guideGoalMapper.queryCountSupervisionByStatus(paraSup);
        return paraSup;
    }

    public GuideGoal queryCountByType(Integer typeId, Map<String, Object> objectMap) {
        objectMap.put("typeId", typeId);
        GuideGoal paraSup = new GuideGoal();
        paraSup.setTypeId(typeId);
        paraSup = guideGoalMapper.queryCountByType(paraSup);
        return paraSup;
    }

    @Override
    public ToJson<GuideGoal> queryCountSupervisionByStatus() {
        ToJson<GuideGoal> toJson = new ToJson<GuideGoal>(1, "error");
        GuideGoal guideGoal = new GuideGoal();
        GuideGoal paraSup = new GuideGoal();
        try {
            int count = guideGoalMapper.queryCountSupervisionByStatus();
            toJson.setTotleNum(count);
            toJson.setFlag(0);
        } catch (Exception e) {
            e.printStackTrace();
            toJson.setFlag(1);
        }
        return toJson;
    }


    /**
     * 作者：张丽军
     * 方法介绍：督办任务查询列表（*********）
     *
     * @param request
     * @return
     */
    public ToJson<GuideGoal> getSupApplyTaskList(Integer status, Integer sid, HttpServletRequest request) {
        ToJson<GuideGoal> toJson = new ToJson<GuideGoal>(1, "error");
        GuideGoal guideGoal = new GuideGoal();
        Cookie redisSessionCookie = CookiesUtil.getCookieByName(request, "redisSessionId");
        Users user = SessionUtils.getSessionInfo(request.getSession(), Users.class, new Users(),redisSessionCookie);
        guideGoal.setUserId(user.getUserId());
        guideGoal.setManagerId(user.getUserId());
        guideGoal.setStatus(status);
        try {
            List<GuideGoal> list = guideGoalMapper.getSupApplyTaskList1(guideGoal);
            if (list != null) {
                for (GuideGoal guideGoal1 : list) {
                    if (!StringUtils.checkNull(guideGoal1.getRealEndTime())) {
                        guideGoal1.setRealEndTime(guideGoal1.getRealEndTime().substring(0, guideGoal1.getRealEndTime().length() - 2));
                    }
                    if (!StringUtils.checkNull(guideGoal1.getEndTime())) {
                        guideGoal1.setEndTime(guideGoal1.getEndTime().substring(0, guideGoal1.getEndTime().length() - 2));
                    }
                    //责任领导人可以有多个，通过解析
                    String nameStringManage = this.checkAll(guideGoal1.getLeaderId());
                    guideGoal1.setUserName(nameStringManage);
                    //协办人可以有多个，通过解析
                    String userid = this.checkAll(guideGoal1.getUserId());
                    guideGoal1.setUserPrivName(userid);

                    //最后一条发聩
                    guideGoal1.setGuideGoalBack(guideGoalBackMapper.getLastBack(guideGoal1.getSid()));
                }
                toJson.setObject(list);
                toJson.setMsg("ok");
            } else {
                toJson.setMsg("空");
            }
            toJson.setFlag(0);
        } catch (Exception e) {
            e.printStackTrace();
            toJson.setMsg(e.getMessage());
            toJson.setFlag(1);
        }
        return toJson;
    }

    public String getString(List<String> Strings) {
        StringBuffer sb = new StringBuffer("");
        for (String s : Strings) {
            sb.append(s);
            sb.append(",");
        }
        return sb.toString();
    }

    /**
     * 作者：张丽军
     * 方法介绍：更新督查督办状态（*********）
     *
     * @param request
     * @return
     */
    public ToJson<GuideGoal> updateSupStatus(GuideGoal guideGoal,
                                             HttpServletRequest request) {
        ToJson<GuideGoal> tojson = new ToJson<GuideGoal>(1, "修改失败！");
        int a = guideGoalMapper.updateByPrimaryKeySelective(guideGoal);
        if(guideGoal.getStatus()!=null && guideGoal.getStatus()==7){
            GuideGoal guideGoal1 = guideGoalMapper.selectByPrimaryKey(guideGoal.getSid());
            addAffairs(guideGoal1,request);
//            addToCalender(supervision1,request);//添加到日程安排
        }
        if(a > 0){
            tojson.setFlag(0);
            tojson.setMsg("操作成功");
        }
        return tojson;
    }



    @Override
    public ToJson<GuideGoal> updateSupervision(HttpServletRequest request, GuideGoal guideGoal) {
        ToJson<GuideGoal> toJson = new ToJson<>(1, "error");
        try {
            guideGoal.setManagerId(guideGoal.getManagerId().substring(0, guideGoal.getManagerId().length() - 1));
            guideGoal.setLeaderId(guideGoal.getLeaderId().substring(0, guideGoal.getLeaderId().length() - 1));
            int a = guideGoalMapper.updateSupervision(guideGoal);
            if (a > 0) {
                toJson.setMsg("ok");
                toJson.setFlag(0);
            } else {
                toJson.setMsg("更新失败");
            }
        } catch (Exception e) {
            e.printStackTrace();
            toJson.setMsg(e.getMessage());
        }
        return toJson;
    }

    /**
     * 给督办添加提醒事务
     * @param guideGoal
     */
    @Async
    public void addAffairs(final GuideGoal guideGoal, HttpServletRequest request) {
        final String sqlType = (String) request.getSession().getAttribute("loginDateSouse");
        Cookie redisSessionCookie = CookiesUtil.getCookieByName(request, "redisSessionId");
        final String userName = SessionUtils.getSessionInfo(request.getSession(), Users.class, new Users(),redisSessionCookie).getUserName();
        this.threadPoolTaskExecutor.execute(new Runnable() {
            @Override
            public void run() {
                ContextHolder.setConsumerType("xoa" + sqlType);
                SmsBody smsBody = new SmsBody();
                smsBody.setFromId(guideGoal.getCreaterId());
                String toUserId="";
                if(!StringUtils.checkNull(guideGoal.getLeaderId())){
                    toUserId+= guideGoal.getLeaderId();
                }
                if(!StringUtils.checkNull(guideGoal.getManagerId())){
                    toUserId+= guideGoal.getManagerId()+",";
                }
                if(!StringUtils.checkNull(guideGoal.getUserId())){
                    toUserId+= guideGoal.getUserId();
                }
                //去重
                if(!StringUtils.checkNull(toUserId)){
                    String[] userArr=toUserId.split(",");
                    List<String> list = new ArrayList<>();
                    list.add(userArr[0]);
                    for(int i=1;i<userArr.length;i++){
                        if(list.toString().indexOf(userArr[i]) == -1){
                            list.add(userArr[i]);
                        }
                    }
                    toUserId="";
                    for(String temp:list){
                        toUserId+=temp+",";
                    }
                }
                smsBody.setContent("方针目标通知：" + guideGoal.getSupName());
                if(!StringUtils.checkNull(guideGoal.getBeginTime())){
                     SimpleDateFormat sdf1 = new SimpleDateFormat(
                            "yyyy/MM/dd HH:mm:ss");
                    String re_time = null;
                    Date d;
                    try {
                        d = sdf1.parse(guideGoal.getBeginTime());
                        long l = d.getTime();
                        String str = String.valueOf(l);
                        re_time = str.substring(0, 10);
                    } catch (ParseException e) {
                        e.printStackTrace();
                    }
                    smsBody.setSendTime(Integer.parseInt(re_time));
                }
                SysCode sysCode = new SysCode();
                sysCode.setCodeName("督办");
                sysCode.setParentNo("SMS_REMIND");
                if (sysCodeMapper.getCodeNoByNameAndParentNo(sysCode) != null) {
                    smsBody.setSmsType(sysCodeMapper.getCodeNoByNameAndParentNo(sysCode).getCodeNo());
                }
                if (!StringUtils.checkNull(guideGoal.getAttachmentId()) && !StringUtils.checkNull(guideGoal.getAttachmentName())) {
                    smsBody.setIsAttach("1");
                }
                smsBody.setRemindUrl("/dljSupervCommon/MySupervision?id=0");
                String title = userName + "督办通知！";
                String context = "主题:" + guideGoal.getSupName();
                smsService.saveSms(smsBody, toUserId, "1", "1", title, context, sqlType);
            }
        });

    }

    /**
     * 作者：郭心雨
     * 方法介绍：添加到日程安排
     * @return
     */
    public void addToCalender(GuideGoal sup, HttpServletRequest request) {
        try {
            Calendar c = new Calendar();
            c.setContent("督办："+sup.getSupName());
            c.setCalType("1");
            c.setEndTime(DateFormat.getDateTime(sup.getEndTime()));
            c.setCalTime(DateFormat.getDateTime(sup.getBeginTime()));
            c.setAddTime(new Date());
            c.setUserId(sup.getCreaterId());
            c.setCalLevel("1");
            c.setBeforeRemaind("0|1|0");
            c.setCalLevel("1");
            c.setOwner(sup.getManagerId()+",");
            if(!StringUtils.checkNull(sup.getUserId())){
                c.setTaker(sup.getLeaderId()+","+sup.getUserId());
            }else{
                c.setTaker(sup.getLeaderId()+",");
            }
            c.setOverStatus("");
            calendarService.insertSelective(c,request);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
